import axios from 'axios'

// http request 拦截器
axios.interceptors.request.use(
    config => {
        let token = '';
        config.headers = {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Accept': 'application/json',
            'Authorization': 'Bearer ' + token
        };
        let hostname = window.location.hostname;
        if (config.params) {
            config.params.hostname = hostname;
        } else {
            config.params = {
                hostname: hostname
            };
        }
        return config;
    },
    err => {
        return Promise.reject(err);
    }
);
axios.interceptors.response.use(
    response => {
        //请求正常则返回
        return Promise.resolve(response)
    },
    error => {
        return Promise.reject(error)
    },
)

export default axios